package com.zb.controller;

import com.zb.entity.Student;
import com.zb.service.PageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @date:2024/11/19 17:41 星期二
 */
@RestController
@RequestMapping("/show")
public class itemController {

    @Autowired
    private PageService service;

    @RequestMapping("/show")
    public String show(Model model) {
        System.out.println("进入控制器...");
        model.addAttribute("msg", "一条测试内容");
        Student student = new Student(1, "张三", 20);
        model.addAttribute("stu", student);
        Student student1 = new Student(1, "张三1", 21);
        Student student2 = new Student(2, "张三2", 25);
        Student student3 = new Student(3, "张三3", 28);

        List<Student> list = new ArrayList<>();
        list.add(student1);
        list.add(student2);
        list.add(student3);
        model.addAttribute("stuList", list);

        model.addAttribute("tag","<a href='www.baidu.com'>百度</a>");
        Map<String,Student> map = new HashMap<>();
        map.put("one",student1);
        map.put("two",student2);
        map.put("three",student3);
        model.addAttribute("stuMap", map);
        return "/index";
    }

    @RequestMapping("/create")
    public String create(@RequestParam("skuId")String skuId){
        service.createPage(skuId);
        return "/item/"+skuId;
    }

}
